package io.renren.modules.labelhistory.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.modules.user.entity.UserinfoEntity;
import io.renren.modules.welderunnormal.entity.WelderunnormalEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.labelhistory.entity.LabelhistoryinfoEntity;
import io.renren.modules.labelhistory.service.LabelhistoryinfoService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2022-08-21 21:59:56
 */
@RestController
@RequestMapping("labelhistory/labelhistoryinfo")
public class LabelhistoryinfoController {
    @Autowired
    private LabelhistoryinfoService labelhistoryinfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    // @RequiresPermissions("labelhistory:labelhistoryinfo:list")
    public R list(@RequestParam Map<String, Object> params){
       // PageUtils page = labelhistoryinfoService.queryPage(params);

        // 分页
        int pageIndex = Integer.parseInt(String.valueOf(params.get("page")));
        int pageSize = Integer.parseInt(String.valueOf(params.get("limit")));
        String labelid = String.valueOf(params.get("key"));
        Page<LabelhistoryinfoEntity> page = new Page<>(pageIndex,pageSize);

        // 通过调用自定义dao层实现
        labelhistoryinfoService.selectByLabelid(labelid,page);

        return R.ok().put("page", page);
    }

    //  获取时间段内的数据
    @GetMapping("listByDate")
    public List<LabelhistoryinfoEntity> listByDate(@RequestParam(value = "key",required = false) String labelId, @RequestParam(value = "startDate",required = false) String startDate, @RequestParam(value = "endDate",required = false) String endDate){
        return labelhistoryinfoService.listByDate(labelId,startDate,endDate);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{labelhistoryNo}")
    @RequiresPermissions("labelhistory:labelhistoryinfo:info")
    public R info(@PathVariable("labelhistoryNo") Integer labelhistoryNo){
		LabelhistoryinfoEntity labelhistoryinfo = labelhistoryinfoService.getById(labelhistoryNo);

        return R.ok().put("labelhistoryinfo", labelhistoryinfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("labelhistory:labelhistoryinfo:save")
    public R save(@RequestBody LabelhistoryinfoEntity labelhistoryinfo){
		labelhistoryinfoService.save(labelhistoryinfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("labelhistory:labelhistoryinfo:update")
    public R update(@RequestBody LabelhistoryinfoEntity labelhistoryinfo){
		labelhistoryinfoService.updateById(labelhistoryinfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("labelhistory:labelhistoryinfo:delete")
    public R delete(@RequestBody Integer[] labelhistoryNos){
		labelhistoryinfoService.removeByIds(Arrays.asList(labelhistoryNos));

        return R.ok();
    }

}
